Ektron CMS400.Net Reference

>>Working with Ektron CSM400.NET Server Controls > Caching with Server Controls

Caching with Server Controls

A key factor in building high-performance, scalable Web applications is the storage of items in memory after the first time they are requested. The items include data objects, pages, and parts of a page.

Known as caching, this process saves and later reuses page output or application data across HTTP requests. You can store items on the Web server or other software in the request stream, such as the proxy server or browser.

Caching saves time and resources because the server does not have to recreate information, particularly things that demand significant processor time or other resources.

The following illustrates data flow in non-cached and cached environments.

Ektron CMS400.NET provides two kinds of caching.

Caching Individual Content - lets you cache part of a Web page; available with some server controls

Page Level Caching - lets you cache an entire page; available with all server controls

Each is explained below.

Caching Individual Content

There are two kinds of caching of individual content.

Caching While not Logged In

Caching While Logged In

Caching While not Logged In

For a description of how Caching While not Logged In works, see Caching with Server Controls.

Caching While Logged In

When a user is logged in, caching prevents any changes from appearing on the site for the number of seconds defined in the cache interval. This reduces the number of database hits, which improves your server’s performance.

For example, if you add a new item to a Collection, the change only appears on the site when the cache interval expires. However, the user can switch to Preview mode to see the updated Collection immediately. See Also: Site Preview

Warning! Caching while logged in does not work with Private content. See Also: Private Content

Setting up Caching of Individual Content

To set up caching of individual content for any Web page, follow these steps.

1. Make sure the Web.config file’s ek_CacheControls property’s value = “1” (one). This is the default. This setting lets you control caching with server controls.

2. Add a server control that supports caching of individual content to a Web form. See The caching of individual content is available for the server controls listed below..

3. Set the server control ‘s CacheInterval property to the length of time the data should be cached. For example, to cache data for five minutes, set CacheInterval to 300 (three hundred).

The default value is 0 seconds. So, you must change the default to enable caching.

Server Controls that Support Caching of Individual Content

The caching of individual content is available for the server controls listed below.

Control

Caching available while not logged in

Caching available while logged in

ActiveTopics

X

 

All blog controls

X

 

Collections

X

X

CommunityDocuments

X

 

CommunityGroupBrowser

X

 

CommunityGroupList

X

 

CommunityGroupMembers

X

 

CommunitySearch

X

 

ContentBlock

X

 

ContentList

X

X

DhtmlMenu

X

X

Directory

X

 

Favorites

X

 

FlexMenu

X

 

FormBlock

X

 

Forum

X

 

Friends

X

 

ListSummary

X

X

MetadataList

X

X

Menu

X

X

Poll

X

 

PostHistory

X

 

SiteMap

X

 

SmartMenu

X

X

TagCloud

X

 

UserProfile

X

 

Page Level Caching

Below is an example of a page level cache for non logged-in users. In this example, you use a Server Control to define whether a user is logged in or not. Then, define if the time is cached, based on the user’s status.

1. Create a new Web form in your Ektron CMS400.NET project.

2. Add the following text to the Web form:
Refresh the page. The page will cache for 20 seconds when not logged in:

Time is =

3. Next to Time is =, add a literal.

4. Below that, add a ContentBlock Server Control.

5. Set the DefaultContentID. For this example, DefaultContentID = 20.

6. Add the following to the Page_Load event in the code behind.


If Not ContentBlock1.IsLoggedIn Then

Response.Cache.SetExpires(DateTime.Now.AddSeconds(20))

Response.Cache.SetCacheability(HttpCacheability.Public)

Response.Cache.SetValidUntilExpires(True)

Response.Cache.VaryByParams("id") = True

Note: On a PageBuilder page, you would use Response.Cache.VaryByParams("pageid") = True.

Response.Cache.SetVaryByCustom("cmsCache")

End If

Literal1.Text = Now()

7. Build your Web form.

8. Browse to your Web form using your browser.

9. Press your browser’s refresh button.

If you are not logged in to Ektron CMS400.NET, the time remains for twenty seconds. After twenty seconds, when you refresh, the new time appears.

Note: You can use the same code in a user control to cache output in a particular region of the page.

Using Ajax Enabled Server Controls and Custom Code


Visit the Ektron Dev Center at http://dev.ektron.com 1-866 - 4 - EKTRON

Ektron CMS400.NET Reference Version 8.02 SP1 Rev 1

Ektron Documentation,© 2011 Ektron, Inc.